#include "graph.h"
#include <bits/stdc++.h>

using namespace std;

// #define LOCK_GETCHAR
// #define USE_INT_128

#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
#endif

#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define ssz(x) (signed((x).size()))
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k)                                                       \
  for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i) // NOLINT
#define eb emplace_back
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
CONSTEXPR_FUNC il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c - '0'); c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on

// File head end

namespace {
int R, n, cnt = 0, nodes, cur, pw[] = {1, 3, 9, 27, 81, 243};
bool key[205 * 205 * 2], vis[205 * 205 * 2];
pii val[205 * 205 * 2];
vector<int> G[205];
void dfs1() {
  n++;
  int deg = NumberOfRoads();
  For(i, 1, deg) {
    int p = ++cnt;
    Move(i, 2);
    int q = LastRoad();
    if (Color() == 1)
      key[p] = vis[p] = 1, dfs1(), Move(q, 3);
    else if (Color() == 3)
      vis[p] = 1, Move(q, 3);
    else
      Move(q, 2);
  }
}
int dfs2(int lst) {
  int v = (++nodes) / pw[cur] % 3 + 1;
  int deg = NumberOfRoads();
  For(i, 1, deg) {
    int p = ++cnt;
    if (key[p]) {
      assert(vis[p]);
      Move(i, v);
      int q = LastRoad(), nxt = dfs2(q);
      val[p].fi += (v - 1) * pw[cur], val[p].se += (nxt - 1) * pw[cur];
    } else if (vis[p]) {
      Move(i, v);
      int q = LastRoad(), nxt = Color();
      val[p].fi += (v - 1) * pw[cur], val[p].se += (nxt - 1) * pw[cur];
      Move(q, nxt);
    }
  }
  if (~lst)
    Move(lst, v);
  return v;
}
int dis[205], ans[205];
void bfs(int x) {
  memset(dis, -1, sizeof dis);
  queue<int> q;
  q.emplace(x), dis[x] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : G[u]) {
      if (!~dis[v]) {
        dis[v] = dis[u] + 1, q.emplace(v);
      }
    }
  }
  For(i, x, n) ans[dis[i]]++;
}
} // namespace

void Inspect(int _R) {
  R = _R;
  dfs1();
  for (cur = 0; cur < 5; cur++)
    nodes = cnt = 0, dfs2(-1);
  For(i, 1, cnt) if (vis[i]) {
    G[val[i].fi].eb(val[i].se), G[val[i].se].eb(val[i].fi);
  }
  For(i, 1, n) bfs(i);
  For(i, 1, R) Answer(i, ans[i]);
}